<%var csstpl = {%>

    </style>
    <%};%>
        <%var jstpl = {%>
            <script>
                var app = new Vue({
                    el: "#content",
                    data: {
                        query: {
                            pageNumber: 1,
                            pageSize: 10,
                            id: '',
                            state: '',
                            create_time: '',
                        },
                        data_result: {},
                    },
                    created: function() {
                        this.loadPage("init")
                    },
                    mounted() {
                        let form = layui.form;
                        let that = this;
                        let date = layui.laydate;
                        date.render({
                            elem: '#createTime', //指定元素
                            type: 'date',
                            range: true,
                            done: function(value, date, endDate) {
                                console.log(that.query.create_time);
                                that.query.create_time = value;

                                console.log(that.query.create_time);
                            }
                        })
                    },
                    methods: {
                        loadPage: function(model) { //载入模式有两种  init初始化载入 load分页载入
                            if (model == "init") {
                                this.query.pageNumber = 1;
                            }
                            Ajax("/system/order/invoice", this.query, function(d) {
                                app.data_result = d;
                                if (d.firstPage == true) {
                                    layui.laypage.render({
                                        elem: 'gexin_page' //注意，这里的 test1 是 ID，不用加 # 号
                                            ,
                                        layout: ['count', 'prev', 'page', 'next',
                                            'limit', 'skip'
                                        ],
                                        count: d.totalRow //数据总数，从服务端得到
                                            ,
                                        limit: app.query.pageSize,
                                        jump: function(obj, first) {
                                            app.query.pageNumber = obj.curr;
                                            if (app.query.pageSize != obj.limit) {
                                                app.query.pageSize = obj.limit;
                                                app.loadPage("init");
                                                return;
                                            }
                                            if (!first) {
                                                app.loadPage("load");
                                            }
                                        }
                                    });
                                }
                            })
                        },
                        changeStatus: function(d) {
                            let that = this;
                            gx.confirm('是否确认将该订单发票状态改为已开票', function() {
                                Ajax('/system/order/invoice/changeStatus/' + d.id, function(res) {
                                    if (res.state) {
                                        gx.alert(res.msg);
                                        that.loadPage('init');
                                    } else {
                                        gx.alert(res.msg);
                                    }
                                })
                            });

                        },
                        allChangeState: function() {
                            let times = this.query.create_time;
                            gx.confirm('是否确认将指定时间内的发票状态改为已开票', function() {
                                Ajax('/system/order/invoice/allChangeState', {
                                    'times': times
                                }, function(res) {
                                    if (res.state) {
                                        gx.alert(res.msg);
                                        that.loadPage('init');
                                    } else {
                                        gx.alert(res.msg);
                                    }
                                })
                            });
                        }

                    }
                })
            </script>
            <%};%>
                <%layout("../layout/_layout_layui.html",{title:"发票管理",jstpl:jstpl,csstpl:csstpl}){%>
                    <div class="layui-row" id="content" v-cloak>

                        <div class="layui-col-md8 layui-inline" style="display: flex">
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label">订单编号</label>
                                <div class="layui-input-inline">
                                    <input type="text" v-model="query.id" placeholder="请输入订单编号模糊查询" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">发票状态</label>
                                <div class="layui-input-inline">
                                    <select v-model="query.state" class="layui-input">
                                        <option value="">请选择状态</option>
                                        <option value="1">未开票</option>
                                        <option value="2">已开票</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">下单时间</label>
                                <div class="layui-input-inline">
                                    <input type="text" v-model="query.create_time" id='createTime' placeholder='开始时间 - 结束时间' autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-col-md3">
                            <div class="layui-form-item">
                                <a @click="loadPage" class="layui-btn"><i class="layui-icon">&#xe615;</i> 查询/筛选</a>
                                <a class="layui-btn" href='/system/order/invoice/downLoadExcle'><i class="layui-icon">&#xe601;</i> 导出</a>
                                <a class="layui-btn" @click='allChangeState()'><i class="layui-icon">&#xe601;</i> 批量开票</a>
                            </div>
                        </div>
                        <!-- 内容开始 -->
                        <div class="layui-col-md12" style="margin-top: 20px">
                            <table class="layui-table ">
                                <thead>
                                    <tr>
                                        <th>订单编号</th>
                                        <th>发票类型</th>
                                        <th>发票状态</th>
                                        <th>发票税号</th>
                                        <th>发票抬头</th>
                                        <th>接收人邮箱</th>
                                        <th>创建时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody v-for="d in data_result.list">
                                    <td>{{d.id }}</td>
                                    <td>{{d.type==1?'个人':'企业' }}</td>
                                    <td>{{d.state==1?'未开票':'已开票' }}</td>
                                    <td>{{d.ein }}</td>
                                    <td>{{d.header }}</td>
                                    <td>{{d.email }}</td>
                                    <td>{{d.create_time }}</td>
                                    <td>
                                        <a class="layui-btn layui-btn-sm" @click="changeStatus(d)" v-if='d.state==1'>已开票</a>
                                    </td>
                                </tbody>
                                <tbody id="tbody_body" v-if="data_result.length==0">
                                    <tr>
                                        <td colspan="8" style="text-align:center;height:300px">
                                            <h1>没有数据</h1>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                            <fieldset id="gexin_page" class="layui-elem-field layui-field-title"></fieldset>
                        </div>


                        <div class="modal fade" id="editAreaFeeModal" tabindex="-1" role="dialog" aria-hidden="true">
                            <form id="addUpdateForm" class="layui-form form-horizontal ">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h4 class="modal-title">
                                                修改代理价格
                                            </h4>
                                        </div>
                                        <div class="modal-body">
                                            <!-- 弹出框开始  -->
                                            <div class="layui-row layui-col-space15">
                                                <!-- 弹出框开始  -->
                                                <input type="hidden" name="area.id">
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label">代理价格</label>
                                                    <div class="layui-input-block">
                                                        <input class="layui-input" type="text" lay-verify="required|number" 　placeholder="请输入要修改的代理价格" name="area.agent_fee">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="modal-footer">
                                            <div class="layui-form-item">
                                                <div class="layui-input-block">
                                                    <button type="button" class="layui-btn" lay-submit lay-filter="submitArea">提交</button>
                                                    <button type="button" data-dismiss="modal" class="layui-btn layui-btn-primary">关闭</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>


                    </div>
                    <%}%>